package com.draven.controller;

import com.draven.common.Result;
import com.draven.service.AccountPasswordService;
import com.draven.service.BookmarkService;
import com.draven.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 首页控制器
 */
@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private AccountPasswordService accountPasswordService;

    @Autowired
    private NoteService noteService;

    @Autowired
    private BookmarkService bookmarkService;

    /**
     * 获取首页统计数据
     */
    @GetMapping("/stat")
    public Result<Map<String, Object>> getStat(HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        
        // 获取账号密码数量
        int accountCount = accountPasswordService.countByUserId(userId);
        
        // 获取笔记数量
        int noteCount = noteService.countByUserId(userId);
        
        // 获取网络地址数量
        int bookmarkCount = bookmarkService.countByUserId(userId);
        
        // 获取收藏网址数量
        int favoriteCount = bookmarkService.countFavoriteByUserId(userId);
        
        Map<String, Object> result = new HashMap<>();
        result.put("accountCount", accountCount);
        result.put("noteCount", noteCount);
        result.put("bookmarkCount", bookmarkCount);
        result.put("favoriteCount", favoriteCount);
        
        return Result.success(result);
    }
} 